package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import pojo.GuestDto;
import pojo.Manager;

public class SelectDao {
	public SelectDao(){
		
	}
	public List<GuestDto>  personinfo(String selectType,String status,String content){
		ConnectDao connectDao = new ConnectDao();
		List<GuestDto> list = new ArrayList<GuestDto> ();
		String sql;
		if(selectType.equals("1")){
			sql = "SELECT * FROM guest WHERE name = '"+content+"' AND personId IN (SELECT personId FROM lives WHERE status = '"+status+"')";
		
		}else if(selectType.equals("2")){
			sql = "SELECT * FROM guest WHERE personId IN (SELECT personId FROM lives WHERE roomNum = '"+content+"' AND status = '"+status+"')";
		}else{
			sql = "SELECT * FROM guest WHERE guestId = '"+content+"' AND guest.personId IN (SELECT personId FROM lives WHERE status = '"+status+"')"; 
		}
		System.out.println("sql = "+sql);
		try{
			ResultSet rs = connectDao.stat.executeQuery(sql);
			while(rs.next()){
				GuestDto gue = new GuestDto();
				gue.name = rs.getString("name");
				gue.sex = rs.getString("sex");
//				gue.roomNum = rs.getString("roomNum");
				gue.tel = rs.getString("tel");
				gue.id = rs.getString("guestId");
				gue.day = rs.getString("day");
				gue.perDay = rs.getString("stayDay");
				gue.personId = rs.getString("personId");
				System.out.println("gue.name"+gue.name);
				list.add(gue);
			}
		}catch(SQLException e){
			e.printStackTrace();
			connectDao.closeConnect();
			return null;
		}
		connectDao.closeConnect();
		return list;
	}
	
	public List<GuestDto>  selectRoom(List<GuestDto> list){
		ConnectDao connectDao = new ConnectDao();
		
		for(int i=0;i<list.size();i++){
			try{
				String sql = "SELECT * FROM lives WHERE personId = '"+list.get(i).personId+"'";
				ResultSet rs = connectDao.stat.executeQuery(sql);
				while(rs.next()){
					list.get(i).roomNum = rs.getString("roomNum");
				}
			}catch(SQLException e){
				e.printStackTrace();
				connectDao.closeConnect();
				return null;
			}
		}
		connectDao.closeConnect();
		return list;
	}
}
